<template>
  <div class="user-view">
    <div class="top-tip">
      <div class="title">我</div>
      <div class="set-icon">
        <div class="icon" v-for="(item, index) in topIconData" :key="index">
          <img class="auto-img" :src="item.icon" />
        </div>
      </div>
    </div>
    <div class="login-area" v-if="token == null" @click="goToLoginView">
      <div class="login-text">登录糗百，体验更多功能</div>
      <div class="login-icon">
        <div class="icon" v-for="(item, index) in logIconData" :key="index">
          <img class="auto-img" :src="item.icon" />
        </div>
      </div>
      <div class="password-to-login">
        账号密码登录 <van-icon name="arrow" />
      </div>
    </div>
    <div class="user-box" v-if="token != null">
      <div class="user-box-left">
        <div class="imgbox">
          <div
            v-if="img != null"
            class="bg"
            :style="{ backgroundImage: 'url(' + img + ')' }"
          ></div>
          <van-uploader :after-read="afterRead" />
        </div>
        <div class="textbox">
          <div class="textbox-top">滴滴答滴答</div>
          <div class="textbox-bottom">
            <div class="view-count">总访客 0</div>
            <div class="today-count">今日 0</div>
          </div>
        </div>
      </div>
      <div class="user-box-right">
        <div class="text">个人主页</div>
        <div class="icon arrow">
          <van-icon name="arrow" />
        </div>
      </div>
    </div>
    <div class="user-data">
      <div
        class="data-box"
        v-for="(item, index) in userData"
        :key="index"
        @click="goToFollowedView(item)"
      >
        <div class="count">{{ item.count }}</div>
        <div class="title">{{ item.title }}</div>
      </div>
    </div>
    <div class="user-history">
      <div
        class="user-history-item"
        v-for="(item, index) in userHistoryData"
        :key="index"
        @click="goToHistoryView(item)"
      >
        <div class="icon">
          <img class="auto-img" :src="item.icon" alt="" />
        </div>
        <div class="title">{{ item.title }}</div>
      </div>
    </div>
    <div class="user-set2">
      <dir
        class="user-set-item"
        v-for="(item, index) in userSetData"
        :key="index"
      >
        <div class="left">
          <div class="icon">
            <img class="auto-img" :src="item.icon" alt="" />
          </div>
          <div class="title">{{ item.title }}</div>
        </div>
        <div class="arrow">
          <span style="color: #888" v-if="item.title == '青少年模式'">{{
            yongerMode == true ? "已开启" : "未开启"
          }}</span
          ><van-icon name="arrow" />
        </div>
      </dir>
    </div>
  </div>
</template>

<script>
export default {
  name: "UserView",
  data() {
    return {
      //顶部夜间模式图标数据
      topIconData: [
        {
          icon: require("@/assets/images/user/uts.png"),
        },
        {
          icon: require("@/assets/images/user/Snipaste_2022-11-19_15-24-23.jpg"),
        },
      ],
      //登录图标数据
      logIconData: [
        {
          icon: require("@/assets/images/user/26u.png"),
        },
        {
          icon: require("@/assets/images/user/GLP.png"),
        },
        {
          icon: require("@/assets/images/user/IV1.png"),
        },
        {
          icon: require("@/assets/images/user/Oph.png"),
        },
      ],
      //用户图标数据
      userData: [
        {
          title: "糗事",
          count: 0,
        },
        {
          title: "动态",
          count: 0,
        },
        {
          title: "关注",
          count: 0,
        },
        {
          title: "粉丝",
          count: 0,
        },
      ],
      //评论收藏图标数据
      userHistoryData: [
        {
          icon: require("@/assets/images/user/03_.png"),
          title: "评论",
        },
        {
          icon: require("@/assets/images/user/XKO.png"),
          title: "收藏",
        },
        {
          icon: require("@/assets/images/user/d6Z.png"),
          title: "商城",
        },
        {
          icon: require("@/assets/images/user/Z0W.png"),
          title: "任务",
        },
        {
          icon: require("@/assets/images/user/Snipaste_2022-11-19_15-22-42.jpg"),
          title: "浏览历史",
        },
      ],
      //底部图标数据
      userSetData: [
        {
          icon: require("@/assets/images/user/WvC.png"),
          title: "每周达人",
        },
        {
          icon: require("@/assets/images/user/Fbo.png"),
          title: "糗百认证",
        },
        {
          icon: require("@/assets/images/user/HQh.png"),
          title: "审核糗事",
        },
        {
          icon: require("@/assets/images/user/Snipaste_2022-11-19_15-23-11.jpg"),
          title: "青少年模式",
        },
        {
          icon: require("@/assets/images/user/y6l.png"),
          title: "联系客服",
        },
      ],
      //青少年模式
      yongerMode: false,
      //登录token值
      token: null,
      //上传头像
      img: null,
    };
  },
  activated() {
    this.token = window.localStorage.getItem("token");
    this.getFollowedData();
  },
  methods: {
    afterRead(file) {
      this.img = file.content;
    },
    //获取已关注
    getFollowedData() {
      let followedData = JSON.parse(
        window.localStorage.getItem("followedData")
      );
      this.userData[2].count=followedData.length
    },
    //跳转关注页面
    goToFollowedView(item) {
      if (item.title == "关注") {
        this.$router.push({ name: "userFollowed" });
      }
    },
    //跳转浏览历史页面
    goToHistoryView(item) {
      if (item.title == "浏览历史") {
        this.$router.push({ name: "historyView" });
      }
    },
    //跳转登录页面
    goToLoginView() {
      this.$router.push({name:'beforeLogin'})
    },
  },
};
</script>

<style lang="scss" scoped>
.user-view {
  width: 100vw;
  height: 100vh;
  padding: 0 10px;
  box-sizing: border-box;
  .top-tip {
    width: 100%;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: right;
    box-sizing: border-box;
    position: relative;
    border-bottom: 1px solid #ddd;
    .title {
      font-size: 18px;
      font-weight: 600;
      width: 100%;
      text-align: center;
    }
    .set-icon {
      display: flex;
      align-items: center;
      position: absolute;
      .icon {
        width: 25px;
        height: 25px;
        border-radius: 999px;
        &:first-child {
          margin-right: 20px;
        }
        &:nth-child(2) {
          margin-top: -4px;
        }
      }
    }
  }
  .login-area {
    width: 100%;
    text-align: center;
    margin: 20px 0;
    font-weight: 600;
    .login-text {
      font-size: 14px;
      margin-bottom: 10px;
    }
    .login-icon {
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      box-sizing: border-box;
      .icon {
        width: 35px;
        height: 35px;
        border-radius: 999px;
        margin: 0 25px;
      }
    }
    .password-to-login {
      width: 100%;
      text-align: center;
      margin-top: 20px;
      font-size: 14px;
      .van-icon-arrow {
        color: #aaa;
      }
    }
  }
  .user-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 10px;
    .user-box-left {
      display: flex;
      .imgbox {
        width: 40px;
        height: 40px;
        border-radius: 999px;
        overflow: hidden;
        margin-right: 10px;
        position: relative;
        .bg {
          position: absolute;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          background: no-repeat center center;
          background-size: cover;
          z-index: 100;
        }
        ::v-deep .van-uploader__upload-icon {
          position: relative;
          top: -20px;
          left: -20px;
        }
        ::v-deep input[type="file"] {
          z-index: 1000;
        }
      }
      .textbox {
        height: 40px;
        padding: 5px 0;
        .textbox-top {
          font-size: 16px;
        }
        .textbox-bottom {
          display: flex;
          color: #999;
          margin-top: 5px;
          .view-count {
            margin-right: 10px;
          }
        }
      }
    }
    .user-box-right {
      display: flex;
      color: #777;
    }
  }
  .user-data {
    display: flex;
    width: 100%;
    justify-content: center;
    align-items: center;
    text-align: center;
    font-size: 16px;
    .data-box {
      width: 35px;
      height: 35px;
      margin: 0 25px;
      .title {
        margin-top: 10px;
        color: #666;
        font-size: 14px;
      }
    }
  }
  .user-history {
    margin-top: 25px;
    padding: 10px;
    width: 100%;
    box-shadow: 0px 0px 6px 1px rgb(235, 235, 235);
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    font-size: 14px;
    border-radius: 5px;
    .user-history-item {
      width: 20%;
      .icon {
        width: 25px;
        height: 25px;
        border-radius: 999px;
        margin: 0 auto 10px;
      }
    }
  }
  .user-set2 {
    width: 100%;
    .user-set-item {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding-left: 10px;
      height: 40px;
      .left {
        display: flex;
        align-items: center;
        font-size: 14px;
        .icon {
          width: 20px;
          height: 20px;
          border-radius: 999px;
          margin-right: 10px;
        }
      }
    }
  }
}
</style>